<template>
  <j-modal :title="title" :width="800" :visible="visible" :maskClosable="false" :fullscreen="true" @close="close">
    <template slot="footer">
      <a-button key="back" style="padding-left: 8px; padding-right: 8px" @click="close(false)"> 关闭 </a-button>
      <a-button
        :disabled="status == '9' || status == '2'"
        v-permission="['40010']"
        type="primary"
        @click="showConfirm"
        style="padding-left: 8px; padding-right: 8px"
      >
        提交审批
      </a-button>
      <a-button
        :disabled="status !== '2'"
        v-permission="['40020']"
        @click="setApproveReason('9')"
        style="padding-left: 8px; padding-right: 8px"
      >
        同意
      </a-button>
      <a-button
        :disabled="status !== '2'"
        v-permission="['40020']"
        type="danger"
        @click="setApproveReason('1')"
        style="padding-left: 8px; padding-right: 8px"
      >
        拒绝
      </a-button>
<!--      <a-button type="danger" key="save" style="padding-left: 8px; padding-right: 8px" @click="setReason()">
        撤销到报告阶段
      </a-button>-->
    </template>
    <div style="margin-bottom: 20px">
      <div class="detail">
        <div class="name">
          {{ model.name }}<span>{{ model.stageText }}</span>
        </div>
        <div class="list">
          <div>
            项目编号：<span>{{ model.number }}</span>
          </div>
          <div>
            项目类别：<span>{{ model.type_dictText }}</span>
          </div>
          <div>
            主审计单位：<span>{{ $store.getters.departInfo.departName }}</span>
          </div>
          <div>
            被审计单位：<span>{{ model.bsjdwName }}</span>
          </div>
          <div>
            审计期间：<span>{{ model.startDate }} ~ {{ model.endDate }}</span>
          </div>
        </div>
      </div>
    </div>
    <div style="margin: 0 auto" :class="{ isCheck: isCheck }">
      <a-tabs type="card" @change="tabsChange" class="tabs_style">
        <a-tab-pane v-for="item in tabs" :key="item.key" :tab="item.title">
          <component
            v-if="isShow && active == item.key"
            :is="`${item.key}`"
            :id="model.id"
            :stage="model.stage"
            :protype="model.type"
            :bsjdwName="model.bsjdwName"
            :bsjdw="model.bsjdw"
            :type="viewTypeId[item.value]"
          ></component>
        </a-tab-pane>
      </a-tabs>
    </div>
    <SelectApprove ref="approver" :id="model.id" @submitData="handleSubmit"></SelectApprove>
    <SetReason ref="setReason" @approveReason="approveData"></SetReason>
    <SetReason ref="chSetReason" @approveReason="returnPro"></SetReason>
  </j-modal>
</template>
<script>
import zgjl from '../commView/zgjl/index'
import zgbcxsjws from '../commView/zgbcxsjws/index'
import zgbg from '../commView/zgbg/index'
import shjl from '../commView/shjl/index'
import { getAction } from '@/api/manage'
import SetReason from '../commView/public/SetReason'
import viewTypeId from '../commView/public/typeId'
import { WORK_AUTH } from '@/store/mutation-types'
import { butStatus } from '../butStatus'
import SelectApprove from '../commView/public/SelectApprover'

export default {
  name: 'contentView',
  components: {
    zgjl,
    zgbcxsjws,
    zgbg,
    shjl,
    SetReason,
    SelectApprove,
  },
  mixins: [butStatus],
  data() {
    return {
      active: 'zgjl',
      viewTypeId: viewTypeId,
      typeId: viewTypeId['审计问题整改'],
      disableSubmit: false,
      title: '',
      visible: false,
      isCheck: false,
      model: {},
      url: {
        returnPro: '/sjxmzygl/sjWorkUsers/recallLastStage',
        permission: '/sys/permission/getButtonByUser',
        submit: '/sjxmzygl/sjWorkUsers/submitAudit',
        approve: '/sjxmzygl/sjWorkUsers/zyApplyCommit',
        butStatus: '/sjxmzygl/sjWorkUsers/queryStageInfo',
      },
      tabs: [
        { key: 'zgjl', title: '整改记录', value: '审计问题整改' },
        { key: 'zgbcxsjws', title: '审计文书模板', value: '审计问题整改' },
        { key: 'zgbg', title: '整改报告', value: '审计问题整改' },
        { key: 'shjl', title: '审核记录', value: '审计问题整改' },
      ],
      isShow: false,
    }
  },
  methods: {
    tabsChange(key) {
      this.active = key
    },
    getWorkAuth() {
      this.isShow = false
      getAction(this.url.permission, { proId: this.model.id }).then((res) => {
        if (res.success) {
          this.isShow = true
          let workAuthData = res.result.workButtonAuth
          sessionStorage.setItem(WORK_AUTH, JSON.stringify(workAuthData))
        }
      })
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.getWorkAuth()
      this.getStstus()
      this.active = 'zgjl'
      this.visible = true
    },
    close() {
      this.visible = false
    },
    setReason() {
      this.$refs.chSetReason.setApproveReason = true
    },
    //撤回
    returnPro(reason) {
      getAction(this.url.returnPro, {
        proId: this.model.id,
        typeId: this.typeId,
        stage: '03010',
        remark: reason,
      }).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.$refs.chSetReason.setApproveReason = false
          this.$emit('ok')
          this.close()
        } else {
          this.$message.error(res.message)
        }
      })
    },
  },
}
</script>

<style lang='less' scoped>
@import '~@assets/less/tableTheme.less';
@import '../../css/checkAndEdit.less';
</style>
